package com.cljz.makepassenger.ui.activity;

import android.content.Intent;
import android.os.Bundle;
import android.widget.EditText;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.cljz.makepassenger.R;
import com.cljz.makepassenger.base.BaseActivity;
import com.cljz.makepassenger.utils.T;
import com.cljz.makepassenger.utils.date.TextUtil;
import com.jakewharton.rxbinding.view.RxView;

import butterknife.BindView;
import cn.droidlover.xdroidmvp.router.Router;
import rx.functions.Action1;

/**
 * Created by apple on 2017/4/25.
 */

public class EditInviteDetailActivity extends BaseActivity {
    @BindView(R.id.iv_back)
    ImageView ivBack;
    @BindView(R.id.fl_back)
    FrameLayout flBack;
    @BindView(R.id.tv_title_name)
    TextView tvTitleName;
    @BindView(R.id.tv_title_right)
    TextView tvTitleRight;
    @BindView(R.id.fl_title_right)
    FrameLayout flTitleRight;
    @BindView(R.id.rl_title)
    RelativeLayout rlTitle;
    @BindView(R.id.et_input_detail)
    EditText etInputDetail;

    @Override
    public void initData(Bundle savedInstanceState) {
        tvTitleName.setText("编辑详情");
        tvTitleRight.setText("完成");
        String hasWrite = getIntent().getExtras().getString("hasWrite");
        if (!TextUtil.isEmpty(hasWrite)) {
            etInputDetail.setText(hasWrite);
            etInputDetail.setSelection(hasWrite.length());
        }
    }

    @Override
    public int getLayoutId() {
        return R.layout.activity_edit_invite_detail;
    }

    @Override
    public Object newP() {
        return null;
    }

    @Override
    protected void initListener() {
        super.initListener();
        RxView.clicks(flBack)
                .compose(this.<Void>bindToLifecycle())
                .subscribe(new Action1<Void>() {
                    @Override
                    public void call(Void aVoid) {
                        Router.pop(EditInviteDetailActivity.this);
                    }
                });
        RxView.clicks(flTitleRight)
                .compose(this.<Void>bindToLifecycle())
                .subscribe(new Action1<Void>() {
                    @Override
                    public void call(Void aVoid) {
                        String detail = etInputDetail.getText().toString().trim();
                        if (TextUtil.isEmpty(detail)) {
                            T.getInstance().showShort("活动描述不能为空");
                        } else {
                            Intent intent = getIntent();
                            Bundle bundle = new Bundle();
                            bundle.putString("detail", detail);
                            intent.putExtras(bundle);
                            setResult(RESULT_OK, intent); //intent为A传来的带有Bundle的intent，当然也可以自己定义新的Bundle
                            Router.pop(EditInviteDetailActivity.this);
                        }
                    }
                });
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
    }
}
